<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <title>[做点有趣的]C&#43;&#43;做一个哈夫曼压缩软件 - Zexun Luo | 罗泽勋</title>
    <meta property="og:title" content="[做点有趣的]C&#43;&#43;做一个哈夫曼压缩软件 - Zexun Luo | 罗泽勋">
    
    <meta name="twitter:card" content="summary">

    
      
    

    
      
      <meta property="description" content="这是以前的一个实训周作业，核心是哈夫曼编码和解码，软件界面由 QT 实现。代码量很小，比较简单。
源代码： https://gitee.com/lzxqaq/zxhan.git
介绍：https://lzxqaq.com/post/zxhan/
算法参考：Huffman压缩真正的C&#43;&#43;实现
运行环境：Linux 系统（Windows系统下运行尚有 bug ),开发环境为 QT Creator。
运 &amp;hellip;">
      <meta property="og:description" content="这是以前的一个实训周作业，核心是哈夫曼编码和解码，软件界面由 QT 实现。代码量很小，比较简单。
源代码： https://gitee.com/lzxqaq/zxhan.git
介绍：https://lzxqaq.com/post/zxhan/
算法参考：Huffman压缩真正的C&#43;&#43;实现
运行环境：Linux 系统（Windows系统下运行尚有 bug ),开发环境为 QT Creator。
运 &amp;hellip;">
      
    

    
    
    <meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/lzxqaq/zxhan@master/images/zxhan.png">
    
    
    
    

    

    
    


<link href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css' rel='stylesheet' type='text/css' />



    <link rel="stylesheet" href="/css/style.css" />
    <link rel="stylesheet" href="/css/fonts.css" />
    
<link rel="stylesheet" href="/css/custom.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.css">  

  </head>

  
  <body class="post">
    <div id="pjax-content">
    <header class="masthead">
      

<h1><a href="/"><img src="/images/logo.png" alt="Zexun Luo" /></a></h1>



      <nav class="menu">
  <ul>
  
  
  <li><a href="/">主页</a></li>
  
  <li><a href="/about/">关于</a></li>
  
  <li><a href="/blog/">日志</a></li>
  
  <li><a href="/post/">技术</a></li>
  
  

  </ul>
</nav>

    </header>
    <article class="main">
      <header class="title">
      
<h1>[做点有趣的]C&#43;&#43;做一个哈夫曼压缩软件</h1>


<h3>
2021-05-25</h3>

<hr>


      </header>



<h3 id="前言">前言</h3>
<p>这是以前的一个实训周作业，核心是哈夫曼编码和解码，软件界面由 QT 实现。代码量很小，比较简单。</p>
<p>源代码： <a href="https://gitee.com/lzxqaq/zxhan.git">https://gitee.com/lzxqaq/zxhan.git</a></p>
<p>介绍：<a href="https://lzxqaq.com/post/zxhan/">https://lzxqaq.com/post/zxhan/</a></p>
<p>算法参考：<a href="https://blog.csdn.net/small_hacker/article/details/52843738">Huffman压缩真正的C++实现</a></p>
<p>运行环境：Linux 系统（Windows系统下运行尚有 bug ),开发环境为 QT Creator。</p>
<p>运行截图：</p>
<div  align="center">    
 <img src="https://cdn.jsdelivr.net/gh/lzxqaq/zxhan@master/images/zxhan.png" width = "500" height = "200" alt="图片名称" align=center /></div>
<!-- ![img](https://cdn.jsdelivr.net/gh/lzxqaq/zxhan@master/images/zxhan.png) -->
<h3 id="核心实现">核心实现</h3>
<pre><code>void create_node_array();//构造包含字符及其频率的数组
void create_pq();//构造优先级队列
void create_huffman_tree();//构造哈夫曼树
void create_map_table(Node* node,bool);//根据哈夫曼树建立哈夫曼映射表
bool calculate_huffman_codes();//计算哈夫曼编码
bool do_compress();//开始压缩
bool rebuid_huffman_tree();//从哈夫曼编码文件中重构哈夫曼树
void decode_huffman();//根据重构的哈夫曼树解码文件

</code></pre><h3 id="后续">后续</h3>
<p>该项目仍有许多不足之处，如果你对该项目有任何意见或建议，欢迎<a href="https://lzxqaq.com/about/">联系我</a>。如有任何问题，亦可与我一同探讨。</p>


  
  <nav class="post-nav">
    <span class="nav-prev">&larr; <a href="/post/paopaotang/">[做点有趣的]Java开发泡泡堂游戏（MVC架构）</a></span>
    <span class="nav-next"><a href="/post/databaseguidelines/">【规约】 MySQL 数据库篇</a> &rarr;</span>
  </nav>
  <script type="text/javascript">
  document.addEventListener('keyup', function(e) {
    if (e.target.nodeName.toUpperCase() != 'BODY') return;
    var url = false;
    if (e.which == 37) {  
      
      url = '\/post\/paopaotang\/';
      
    } else if (e.which == 39) {  
      
      url = '\/post\/databaseguidelines\/';
      
    }
    if (url) window.location = url;
  });
  </script>
  
  </article>
  </div>
  <footer>
  
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="/js/jquery.pjax.js"></script>
<script src="/js/pjax.config.js"></script>

<div class="music">
<div id="player" class="aplayer"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.js"></script>  

<script type="text/javascript">
const ap = new APlayer({
    container: document.getElementById('player'),
    order: 'random',
    listFolded: true,
    listMaxHeight: 90,
    theme:	'#b7daff',
    audio: [
    {
        name: 'きこえるかしら',
        artist: '大和田りつこ',
        url: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/music/赤毛のアンOP_きこえるかしら_大和田りつこ.mp3',
        cover: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/image/赤毛のアンOP_きこえるかしら_大和田りつこ.jpeg'
      },
      {
        name: 'まっててごらん',
        artist: '大杉久美子',
        url: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/music/大杉久美子_ネリー・シュワルツ_まっててごらん.mp3',
        cover: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/image/大杉久美子_ネリー・シュワルツ_まっててごらん.png'
      },
      {
        name: 'ペリーヌ物語',
        artist: '片头曲和片尾曲',
        url: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/music/世界名作劇場_ペリーヌ物語_OP_ED.mp3',
        cover: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/image/世界名作劇場_ペリーヌ物語_OP_ED.jpg'
      },
      {
        name: 'ほほえみの魔法',
        artist: 'トラップ一家物語',
        url: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/music/Trapp_Family_Story_Hohoemi_no_mahou_ほほえみの魔法_Smil.mp3',
        cover: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/image/Trapp_Family_Story_Hohoemi_no_mahou_ほほえみの魔法_Smil.jpg'
      },
      {
        name: 'It is a Small world',
        artist: 'Disney Classics',
        url: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/music/Disney_Classics_It_s_a_Small_World_It_s_a_Small.mp3',
        cover: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/image/Disney_Classics_It_s_a_Small_World_It_s_a_Small.jpg'
      },
      {
        name: 'Forrest Gump Suite',
        artist: 'Alan Silvestri',
        url: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/music/Alan_Silvestri_Forrest_Gump_Suite2.mp3',
        cover: 'https://cdn.jsdelivr.net/gh/lzxqaq/jsdelivr@master/image/Alan_Silvestri_Forrest_Gump_Suite.jpeg'
      },





  ]
});
</script>




<script async src="/js/fix-toc.js"></script>

<script async src="/js/center-img.js"></script>

<script async src="/js/right-quote.js"></script>

<script async src="/js/no-highlight.js"></script>

<script async src="/js/fix-footnote.js"></script>

<script async src="/js/math-code.js"></script>

<script async src="/js/external-link.js"></script>

<script async src="/js/alt-title.js"></script>

<script async src="/js/header-link.js"></script>




  



<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>



<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/r.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/yaml.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/tex.min.js"></script>
<script>hljs.configure({languages: []}); hljs.initHighlightingOnLoad();</script>



  
  <hr>
  <div class="copyright">© <a href="/">Zexun Luo</a> 2020 - 2021</div>
  
  </footer>
  
  </body>
</html>

